/**
 * @param {character[]} chars
 * @return {number}
 */
var compress = function (chars) {
    let write = 0
    let read = 0

    while (read < chars.length) {
        const currentChar = chars[read]
        let count = 0
        while (read < chars.length && chars[read] === currentChar) {
            read++
            count++
        }
        chars[write++] = currentChar
        if (count > 1) {
            const countStr = count.toString()
            for (const c of countStr) {
                chars[write++] = c
            }
        }
    }
    return write
};
console.log(compress(["a", "a", "b", "b", "c", "c", "c"]));
